package com.lxmes.business.service.impl;

import java.util.List;

import com.lxmes.business.domain.CcHkMain;
import com.lxmes.business.mapper.CcHkMainMapper;
import com.lxmes.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lxmes.business.mapper.CcHkInfoMapper;
import com.lxmes.business.domain.CcHkInfo;
import com.lxmes.business.service.ICcHkInfoService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 回款明细Service业务层处理
 * 
 * @author 张志煜
 * @date 2022-08-27
 */
@Service
public class CcHkInfoServiceImpl implements ICcHkInfoService 
{
    @Autowired
    private CcHkInfoMapper ccHkInfoMapper;

    @Autowired
    private CcHkMainMapper ccHkMainMamapper;

    /**
     * 查询回款明细
     * 
     * @param id 回款明细主键
     * @return 回款明细
     */
    @Override
    public CcHkInfo selectCcHkInfoById(Long id)
    {
        return ccHkInfoMapper.selectCcHkInfoById(id);
    }

    /**
     * 查询回款明细列表
     * 
     * @param ccHkInfo 回款明细
     * @return 回款明细
     */
    @Override
    public List<CcHkInfo> selectCcHkInfoList(CcHkInfo ccHkInfo)
    {
        return ccHkInfoMapper.selectCcHkInfoList(ccHkInfo);
    }

    /**
     * 新增回款明细
     * 
     * @param ccHkInfo 回款明细
     * @return 结果
     */
    @Transactional
    @Override
    public int insertCcHkInfo(CcHkInfo ccHkInfo)
    {
        ccHkInfo.setCreateTime(DateUtils.getNowDate());
        CcHkMain ccHkMain = ccHkMainMamapper.selectCcHkMainById(ccHkInfo.getMainId());
        ccHkMain.setHkTotalMoney(ccHkInfo.getRes1().add(ccHkMain.getHkTotalMoney()));
        ccHkMainMamapper.updateCcHkMain(ccHkMain);
        return ccHkInfoMapper.insertCcHkInfo(ccHkInfo);
    }

    /**
     * 修改回款明细
     * 
     * @param ccHkInfo 回款明细
     * @return 结果
     */
    @Override
    public int updateCcHkInfo(CcHkInfo ccHkInfo)
    {
        ccHkInfo.setUpdateTime(DateUtils.getNowDate());
        return ccHkInfoMapper.updateCcHkInfo(ccHkInfo);
    }

    /**
     * 批量删除回款明细
     * 
     * @param ids 需要删除的回款明细主键
     * @return 结果
     */
    @Override
    public int deleteCcHkInfoByIds(Long[] ids)
    {
        return ccHkInfoMapper.deleteCcHkInfoByIds(ids);
    }

    /**
     * 删除回款明细信息
     * 
     * @param id 回款明细主键
     * @return 结果
     */
    @Override
    public int deleteCcHkInfoById(Long id)
    {
        return ccHkInfoMapper.deleteCcHkInfoById(id);
    }
}
